package com.hbt.user_consumer.service;

import com.hbt.api.entity.CommonResult;
import com.hbt.user_consumer.config.FeignMultipartSupportConfig;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

//@FeignClient(value = "user-upload-provider", configuration = UserUploadServiceFeign.MultipartSupportConfig.class)
@FeignClient(value = "user-upload-provider", configuration = UserUploadServiceFeign.MultipartSupportConfig.class)
public interface UserUploadServiceFeign {

    String pre = "user_upload";
//    @PostMapping(value = "user_upload/uploadAvatar", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @RequestMapping(method = RequestMethod.POST,value = "user_upload/uploadAvatar",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public CommonResult uploadAvatar();

    @PostMapping("user_upload/test")
    public String test();

    @Configuration
    class MultipartSupportConfig {
        //        @Bean
//        public Encoder feignFormEncoder() {
//            return new SpringFormEncoder(new SpringEncoder(messageConverters));
//        }
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }

//    @Configuration
//    class MultipartSupportConfig {
//        @Autowired
//        private ObjectFactory<HttpMessageConverters> messageConverters;
//
//        @Bean
//        public Encoder feignFormEncoder() {
//            return new SpringFormEncoder(new SpringEncoder(messageConverters));
//        }
//    }
}
